<template>
  <view class="index">
    <u-swiper :list="index_swiper"
              height="169px"
              keyName="path"></u-swiper>
			  <view class="" style="display: flex;align-items: center;padding: 5rpx;">
			  	<image src="../../static/images/gonggao.png" mode="widthFix" style="width: 30rpx;"></image>
			  	<view class="container">  
			  	    <view class="scroll-text">  
			  	      {{ text }}  
			  	    </view>  
			  	  </view> 
			  </view> 
    <view class="index-nav model m-flex m-row-between">
      <view class="fast_buy">
        <view @click="openKF(KF)">
          <image src="/static/images/index_charge.png"
                 mode="widthFix"></image>
        </view>
        <view @click="openKF(KF)"
              class="text-cz">
          <view class="luick-recharge">快捷充值</view>
          <view style="color:#828095">银行转账和多种方式选择</view>
        </view>
        <view @click="openKF(KF)"
              class="">
          <image src=""
                 mode=""
                 style=""
                 class="image-tz" />
        </view>
      </view>
      <!-- <view class="recharge-option">
				<navigator class="m-flex c-box c-right-item" url="/pages/mine/msg_view?id=2">
					<m-image src="/static/images/guanyu.png" width="1.5em"></m-image>关于我们
				</navigator>
				<navigator @click="openKF(KF)" class="m-flex c-box c-right-item">
					<m-image src="/static/images/my2.png" width="1.5em"></m-image>在线客服
				</navigator>
			</view> -->
    </view>
    <view class="index-increase">
      <!-- <view class="index-increase-title p4 model">涨幅榜</view>
			<view class="" style="padding: 0 30rpx;">
				<view class="table-title cc-row-between">
					<view class="cc-cols-1">
						LOGO
					</view>
					<view class="cc-cols-2">
						名称
					</view>
					<view class="cc-cols-3">
						最新价
					</view>
					<view class="cc-cols-4">
						交易状态
					</view>
				</view> -->
      <view class="product-list">
        <view class="product-info"
              v-for="(item,index) in products"
              :key="item.id"
              @click="toTrade(item)"
              v-if="item.isdelete==0">
          <view class="info">
            <view class=" ">
              <image :src="item.img|filterImg"
                     class="info-img"  :style="index>3?'height:150px':'htight:100px;'"></image>
            </view>
            <view class="info-name ">
              <view class="">
                {{item.title}}
              </view>
            </view>
            <view class="info-price">
              <text class="jy">{{item.is_deal==0?'休市':'交易'}}</text>
              <text :class="item.is_rise==2?'lvse':'honse'">{{item.Price}}</text>
            </view>
          </view>
          <!-- <view class="cc-line">
          </view> -->
        </view>
      </view>
    </view>
  </view>
  </view>
</template>

<script>
// 引入请求
import {
  url,
  getMenu,
  getProducts,
  updateProducts,
  gdArticle
} from '../../config/api.js'
export default {
  data () {
    return {
      index_swiper: [], //轮播图
      products: [], //交易对
      productsTime: 0, //交易对定时器
      KF: uni.getStorageSync('KF'),
	  text: ''
    }
  },
  // 计算属性
  computed: {
    // 过滤图片
    userkf () {
      // return this.KF
      // 读取缓存中的数据
      let KF = uni.getStorageSync('KF')
      if (KF) {
        return KF
      } else {
        return ''
      }
    }
  },
  onLoad () {
    this.getSwiper() //获取轮播图
  },
  onShow () {
    this.myGetProducts() //获取底部交易对

  },
  onHide () {
    this.myClearInterval(this.productsTime)
    this.productsTime = null
  },
  methods: {
    GotoKF () {
      uni.navigateTo({
        url: this.userkf
      })
    },
    // 前往交易市场
    toTrade (item) {
      this.$Router.pushTab(`/pages/trade/trade`)
      uni.setStorageSync('trade_pid', {
        id: item.id,
        title: item.title
      })
    },
    // 获取轮播图
    getSwiper () {
      getMenu().then(res => {
        // console.log('轮播图', res);
        // 拼接路径
        res.data.map(value => {
          value.path = url + value.path
        })
        this.index_swiper = res.data
      })
	  gdArticle().then(res=>{
		  let s='';
		  res.data.forEach(e=>{
			  s=s+'  '+e.title
		  })
		  this.text=s
	  })
    },
    // 获取底部交易对
    myGetProducts () {
      const that = this
      getProducts().then(async res => {
        // console.log('底部交易对', res);
        this.products = res.data
        // 存入缓存
        uni.setStorageSync('storage_key', res.data);
        this.myUpdateProducts()
        // 开启定时更新任务
        this.productsTime = setInterval(() => {
          this.myUpdateProducts()
        }, 2000)
      })
    },
    // 更新产品波动
    myUpdateProducts () {
      updateProducts().then(res => {
        // console.log('更新产品波动', res);
        res.data.map(value => {
          let index = this.products.findIndex(item => item.id == value.id)
          if (index != -1) {
            this.products[index].Price = value.Price
            this.products[index].isdelete = value.isdelete
            this.products[index].is_rise = value.is_rise
            this.products[index].is_deal = value.is_deal
          }
        })
      })
    },
    // 删除多余定时器
    myClearInterval (end) {
      if (!end) {
        end = 1000
      }
      for (let i = 0; i <= end; i++) {
        clearInterval(i)
      }
    },
    // 客服
    getService () {
      service().then(res => {
        console.log('客服', res);
        this.KF = res.data
        uni.setStorageSync('KF', res.data)
      })
    },
    // 打开客服
    openKF (value) {
      // window.open(value)
	  uni.navigateTo({
	  	url:'/pages/mine/recharge1'
	  })
    },
  }
}
</script>

<style lang="scss" scoped>
	.container {  
		flex: 1;
	  overflow: hidden; /* 隐藏超出部分 */  
	  // height: 50px;    /* 高度可根据需要调整 */
		  background-color: #25252f;
	}  
	
	.scroll-text {  
		  display: inline-block; /* 使内容不换行 */  
	  white-space: nowrap; /* 不换行 */  
	  animation: scroll 30s linear infinite; /* 10秒滚动，并无限循环 */  
	  font-size: 20rpx;
	  animation-delay: 0s;
	
	  padding: 5rpx 0;
	}  
	
	@keyframes scroll {  
	  0% {  
	    transform: translateX(50%); /* 从右侧进入 */  
	  }  
	  100% {  
	    transform: translateX(-100%); /* 向左侧离开 */  
	  }  
	}  
  .product-list {
    display: flex;
    flex-wrap: wrap;
    padding-left: 20rpx;
    padding-right: 20rpx;
    // margin: 0 auto;
    .product-info {
      width: 50%;
      margin-top: 10px;
      .info {
        padding: 10px;
        background-color: #262630;
        font-size: 12px;
        font-weight: 700;
        color: #828095;
        .info-img {
          background-color: #2d2d38;
          width: 100%;
          height: 100px;
          border-radius: 5px;
		  display: flex;
		   // 第五个样式  
		   
        }
      }
      .info-name {
        margin-top: 10px;
        margin-bottom: 10px;
        background-color: #262630;
        font-size: 12px;
        font-weight: 700;
        color: #ffffff;
      }
      .info-price {
        display: flex;
        .lvse {
          color: green;
        }
        .honse {
          color: #ff0000;
        }
        .jy {
          color: #ffffff;
          margin-right: auto;
        }
      }
    }
  }

  .fast_buy {
    height: 71px;
    display: flex;
    align-items: center;
    background-color: #25252f;
    margin: 0 -15px;
    padding: 0 15px;

    width: 100%;
    margin: 0 auto;
    .text-cz {
      font-size: 14px;
      color: #fff;
      margin-left: 10px;
      margin-right: auto;
    }
    .image-tz {
      width: 26px;
      height: 26px;
    }
  }

  // ============================== //
  .table-item {
    margin-bottom: 30rpx;
  }

  .cc-line {
    height: 6rpx;
    background-image: linear-gradient(to right, #464646, #fff, #464646);
    margin-top: 30rpx;
  }

  .cc-row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .cc-cols-1 {
    width: 20%;
  }

  .cc-cols-2 {
    width: 35%;
  }

  .cc-cols-3 {
    width: 25%;
    max-width: 25%;
    min-width: 25%;
    text-align: center;
  }

  .cc-cols-4 {
    width: 20%;
    text-align: right;
  }

  .c-box {
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 12rpx;
  }

  .c-left {
    width: 60%;
    height: 100%;
  }

  .c-row-around {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }

  .c-right-item {
    height: 45%;
    width: 95%;
    justify-content: center;
  }

  .index-nav {
    color: #d5d7d0;
    line-height: 1.5;
    height: 160rpx;

    .luick-recharge {
      color: #fff;
      font-size: 36rpx;
      font-weight: 600;
    }

    .recharge-option {
      color: #fff;
      width: 40%;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      align-items: flex-end;

      .m-image-wrap {
        margin-right: 0.5em;
      }
    }

    image {
      width: 80rpx;
      margin-right: 10px;
    }
  }

  .rise {
    background-color: rgb(38, 168, 72);
    padding: 0.6rem 0.8rem;
    border-radius: 0.6rem;
  }

  .fall {
    background-color: rgb(255, 1, 5);
    padding: 0.6rem 0.8rem;
    border-radius: 0.6rem;
  }

  .index-increase {
    .index-increase-title {
      color: #00ffff;
    }

    .increase-list {
      padding: 0 $m-padding;
      background-color: rgb(34, 38, 41);

      .new-money {
        min-width: 9rem;
      }

      .increase-title {
        max-width: 8rem;
      }
    }
  }
</style>
